package com.guoli.sms.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.guoli.sms.service.ISysuserService;
import com.guoli.sms.service.impl.SysuserServiceImpl;
import com.guoli.sms.vo.SmsSession;
import com.guoli.sms.vo.Sysuser;


/**
 * @author zhuxiaodong
 *
 */
public class LoginAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ISysuserService sysuserService = new SysuserServiceImpl();
		
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		Sysuser sysuser = sysuserService.getSysuserByNP(name, password);
		if(sysuser != null){
			request.getSession().setAttribute("sysuser", sysuser);
			request.getSession().setAttribute("smssession", new SmsSession());
			System.out.println("login...");
			response.sendRedirect(this.getServletContext().getContextPath()+"/LoginServlet?opt=indexUI");
		}else{
			response.sendRedirect(this.getServletContext().getContextPath()+"/LoginServlet?opt=loginUI");
		}
	}
}
